package com.benhaile.action;

import com.alibaba.fastjson.JSON;
import com.benhaile.beans.User;
import com.benhaile.common.JsonMsg;
import com.benhaile.oschina.TweetApi;
import com.benhaile.oschina.UserApi;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by oschina on 2014/8/6.
 */
@WebServlet("/action/tweet")
public class TweetAction extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user_id = request.getParameter("user_id");
        String tweet = request.getParameter("tweet");

        if(!StringUtils.isNumeric(user_id))
            return;

        String access_token =  Oauth2Action.Users().get(Long.valueOf(user_id));

        if(null == access_token){
            JsonMsg.json_out(JsonMsg.jsonError("请重新认证！", JsonMsg.ERROR_CODE_AUTH), response);
            return;
        }
        String ret= TweetApi.postPub(access_token,tweet);

    }
}
